package com.app.micaihu.view.newsdetail.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.news.RecommendGalleryEntity;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.image.LoadImageUtils;

import java.util.List;

/**
 * Created by Guo on 2016/7/29.
 *
 * 图片详情中相关图片的gridview 的adapter
 *
 */
public class ImageDetailAboutAdapter extends AppBaseAdapter<RecommendGalleryEntity>{


    private List<RecommendGalleryEntity> list;

    public ImageDetailAboutAdapter(List<RecommendGalleryEntity> list, Context context) {
        super(list, context);
        this.list = list;
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_imagedetail_about,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        RecommendGalleryEntity recommendGalleryEntity = list.get(position);
        if(recommendGalleryEntity != null && !TextUtils.isEmpty(recommendGalleryEntity.getArticleId())
                && !TextUtils.isEmpty(recommendGalleryEntity.getArticleThumb())
                && !TextUtils.isEmpty(recommendGalleryEntity.getArticleTitle())){

            viewHolder.tvTitle.setText(recommendGalleryEntity.getArticleTitle());
            LoadImageUtils.getInstance().loadImage(viewHolder.civPic,recommendGalleryEntity.getArticleThumb());

            convertView.setTag(R.id.aboutImageGridView,recommendGalleryEntity);

        }

        return convertView;
    }


    class ViewHolder{
        CustomImageView civPic;
        TextView tvTitle;

        ViewHolder(View convertView){
            civPic = (CustomImageView) convertView.findViewById(R.id.civ_pick);
            tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
        }
    }




}
